<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width">
    <script type="text/javascript" src="${ctx}/static/js/jquery.min.js"></script>
    <script type="text/javascript" src="${ctx}/static/js/avalon.shim.js"></script>
    <script type="text/javascript" src="${ctx}/static/layui/layui.js" charset="utf-8"></script>
    <link href="${ctx}/static/css/login.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="${ctx}/static/layui/css/layui.css" media="all"/>
</head>
<body ms-controller="main">
<div class="login">
    <div class="logo" style="">动车组巡检过程管理系统</div>
    <div class="login_form">
        <div class="user">
            <input class="text_value" type="text" ms-duplex="loginname" placeholder="请输入用户名">
            <input class="text_value" type="password" ms-duplex="password" placeholder="请输入密码">
        </div>
        <button class="button" type="button" onclick="checkUser()">登录</button>
    </div>
    <div class="foot">Copyright &copy; 2014-2017.武汉中科鑫海科技有限公司.</div>
</div>
</body>
<script>
    var vm;
    avalon.ready(function () {
        vm = avalon.define({
            $id: "main",
            loginname: "",
            password: "",
            errmsg: "",
            resetUser: function () {
                vm.username = '';
                vm.password = '';
            }
        })
        avalon.scan();
    });
    layui.use('layer', function () {
        var layer = layui.layer;
    });
    function checkUser() {
        if (vm.$model.loginname == '') {
            layui.layer.alert('登录名不能为空', {
                closeBtn: 0
            });
            return;
        }
        if (vm.$model.password == '') {
            layui.layer.alert('密码不能为空', {
                closeBtn: 0
            });
            return;
        }
        layui.layer.msg('正在加载...', {
            time: 0,
            icon: 16
            , shade: 0.02
        });
        var data = {loginname: vm.$model.loginname, password: vm.$model.password};
        $.ajax({
            type: 'post',
            url: '${ctx}/checkUser.action',
            data: data,
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    layui.layer.closeAll();
                    window.location.href = "${ctx}/toMain.action";
                } else if (data.code == -1) {
                    layui.layer.alert('用户名不存在', {
                        closeBtn: 0
                    });
                } else {
                    layui.layer.alert('密码不正确', {
                        closeBtn: 0
                    });
                }

            }
        });
    }
    $(function () {
        document.onkeydown = function (e) {
            var ev = document.all ? window.event : e;
            if (ev.keyCode == 13) {
                checkUser();
            }
        }
    });
</script>
</html>